package com.code.demo.ui.common;

import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.code.demo.R;


public class DialogFlowLayout {

    private Dialog mDialog;
    private FlowLayout flow;

    public DialogFlowLayout(Context context) {

        LayoutInflater inflater = LayoutInflater.from(context);
        View view = inflater.inflate(R.layout.widget_dialog_flowlayout, null);

        mDialog = new Dialog(context, R.style.dialog);
        mDialog.setContentView(view);
        mDialog.setCanceledOnTouchOutside(true);
        mDialog.setOnKeyListener(new DialogInterface.OnKeyListener() {
            @Override
            public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
                if (keyCode == KeyEvent.KEYCODE_BACK) {
                    return true;
                }
                return false;
            }
        });

        flow = (FlowLayout) view.findViewById(R.id.layout);
        flow.removeAllViews();
        TextView tv1 =  (TextView) inflater.inflate(R.layout.widget_text, flow, false);
        tv1.setText("1234567890");
        flow.addView(tv1);
        TextView tv2 =  (TextView) inflater.inflate(R.layout.widget_text, flow, false);
        tv2.setText("1234");
        flow.addView(tv2);
        TextView tv3 =  (TextView) inflater.inflate(R.layout.widget_text, flow, false);
        tv3.setText("1");
        flow.addView(tv3);
        TextView tv4 =  (TextView) inflater.inflate(R.layout.widget_text, flow, false);
        tv4.setText("1234567890");
        flow.addView(tv4);
        TextView tv5 =  (TextView) inflater.inflate(R.layout.widget_text, flow, false);
        tv5.setText("123456");
        flow.addView(tv5);
    }

    public void show() {
        mDialog.show();
    }

    public void dismiss() {
        mDialog.dismiss();
    }

}
